package cn.iocoder.devlop.module.annual.report.wssubcapital.controller.app;

import cn.iocoder.devlop.framework.common.pojo.CommonResult;
import cn.iocoder.devlop.module.annual.report.wssubcapital.controller.vo.WsSubcapitalOverwriteVO;
import cn.iocoder.devlop.module.annual.report.wssubcapital.controller.vo.WsSubcapitalRespVO;
import cn.iocoder.devlop.module.annual.report.wssubcapital.convert.WsSubcapitalConvert;
import cn.iocoder.devlop.module.annual.report.wssubcapital.dal.dataobject.WsSubcapitalDO;
import cn.iocoder.devlop.module.annual.report.wssubcapital.service.WsSubcapitalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.devlop.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 外商年报投资者信息")
@RestController
@RequestMapping("/annual/report/ws-subcapital")
@Validated
public class AppWsSubcapitalController {

    @Resource
    private WsSubcapitalService wsSubcapitalService;

    @GetMapping("/list")
    @Operation(summary = "获得外商投资者基本信息列表")
    public CommonResult<List<WsSubcapitalRespVO>> getWsSubcapitalList(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        List<WsSubcapitalDO> wsSubcapitals = wsSubcapitalService.getWsSubcapitalList(regno, ancheyear);
        return success(WsSubcapitalConvert.INSTANCE.convertList(wsSubcapitals));
    }

    @PutMapping("/overwrite")
    @Operation(summary = "覆盖更新外商投资者基本信息")
    public CommonResult<Boolean> overwriteWsSubcapital(@Valid @RequestBody WsSubcapitalOverwriteVO updateReqVO) {
        wsSubcapitalService.overwriteWsSubcapital(updateReqVO);
        return success(true);
    }

}
